package DocketManage

import (
	"MedicalTreatment/global"
	model "MedicalTreatment/model"
	"fmt"
	"github.com/gin-gonic/gin"
)

func DocSel(r *gin.Engine) {
	r.POST("/selDoc", func(context *gin.Context) {
		var res model.Docket
		if err := context.ShouldBindJSON(&res); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
			return
		}
		var doc []model.Docket
		//var docdep model.Docket
		term := global.DB.Model(&model.Docket{})
		if res.Name != "" {
			term.Where("name LIKE ? ", res.Name+"%")
		}
		if res.Docket_department != nil {
			term.Where("docket_department = ?", res.Docket_department)
		}
		if res.Expert != nil {
			term.Where("expert = ?", res.Expert)
		}
		if res.Qualification != nil {
			term.Where("qualification = ?", res.Qualification)
		}
		if err := term.Debug().Find(&doc).Error; err != nil {
			context.JSON(200, gin.H{
				"Msg": "查询失败",
			})
		} else {
			fmt.Println(doc)
			context.JSON(200, gin.H{
				"Msg": doc,
			})
		}
	})
}
